{extend name="base" /}
{block name="body"}
<style type="text/css">
.mleft {
    margin-right: 10px;
}
</style>
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">游戏方结算</li>
            <li><a href="{:url('/admin/settle/gaode')}">渠道结算（高德）</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
             <div class="layui-form-item">
                <form class="layui-form layui-form-pane" action="{:url('/admin/settle/index')}" method="get">

                    <div class="layui-inline mleft">
                        <label class="layui-form-label">CP名称</label>
                        <div class="layui-input-block">
                            <select name="cp_id" lay-search>
                                <option value="">请选择游戏研发</option>
                                {foreach name=":get_cp_list()" item="vo"}
                                    <option value="{$vo.id}"{if condition="$vo['id'] eq input('cp_id')"}selected{/if}>{$vo.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

{/*                    <div class="layui-inline mleft">*/}
{/*                        <label class="layui-form-label">选择渠道</label>*/}
{/*                        <div class="layui-input-inline" style="width: 130px;">*/}
{/*                            <select name="cid" lay-filter="cid" id="cid" lay-search>*/}
{/*                                <option value="">请选择渠道</option>*/}
{/*                                {foreach name=":get_channel_list()" item="vo"&cc;*/}
{/*                                    <option value="{$vo.id&cc;"{if condition="input('cid') == $vo.id"&cc; selected{/if&cc;>{$vo['platform']&cc;</option>*/}
{/*                                {/foreach&cc;*/}
{/*                            </select>*/}
{/*                        </div>*/}
{/*                    </div>*/}

                    <div class="layui-inline mleft">
                        <label class="layui-form-label">选择游戏</label>
                        <div class="layui-input-inline" style="width: 130px;">
                            <select name="gid" lay-filter="gid" id="gid" lay-search>
                                <option value="">请选择游戏</option>
                                {foreach name="game_list" item="vo"}
                                    <option value="{$vo.id}"{if condition="input('gid') == $vo.id"} selected{/if}>{$vo['name']}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline mleft">
                        <label class="layui-form-label">范围选择</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <input name="starttime" value="{:input('starttime')}" class="layui-input" placeholder="开始时间" id="starttime">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                    </div>
                </form>
              </div>
                <hr>

                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>日期</th>
                        {/*<th>游戏名称</th>*/}
                        <th>游戏供应商</th>
                        <th>总充值</th>
						<th>游戏分成</th>
                        <th>通道费</th>
                        {/*<th>渠道分成</th>*/}
                        <th>艾七分成</th>
                        <th>查看游戏分成详情</th>
                        <th>结算预览</th>
                        <th>结算状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {if condition="$counts > 0"}
                        {foreach name="list" item="vo"}
                        <tr>
                            <td>{$vo['date_month']}</td>
                            {/*<td>{:get_game_filed($vo['gid'],'name')&cc;</td>*/}
                            <td>{:get_cp_name($vo['cp_id'])}</td>
                            <td>{$vo['amount']}</td>
                            <td>{:round($vo['g_fencheng'],2)}</td>
                            <td>{:round($vo['g_fee'],2)}</td>
                            {/*<td>{:round($vo['c_fencheng'],2)&cc;</td>*/}
                            <td>{:round($vo['amount'] - $vo['g_fencheng'] - $vo['c_fencheng'],2)}</td>
                            <td style="text-align: center">
                                <a href="{:url('/admin/settle/detail',['cp_id'=>$vo['cp_id'],'date_month'=>strtotime($vo['date_month']),'type'=>1])}" class="layui-btn layui-btn-normal layui-btn-mini">查看详情</a>
                            </td>
                            <td>
                                <a  target="_blank" href="{:url('/admin/settle/yulan',['cp_id'=>$vo['cp_id'],'date_month'=>strtotime($vo['date_month']),'type'=>1])}" class="layui-btn layui-btn-normal layui-btn-mini">预览</a>
                            </td>
                            <th>{if condition="$vo['status'] eq 0"}未结算{else、}已结算{/if}</th>
                            <td>
                                {if condition="$vo['status'] eq 0"}
                                    <a onclick="Settle(this)" data-id="{$vo['cp_id']}" data-date="{$vo['date_month']}" class="layui-btn layui-btn-normal layui-btn-mini">结算</a>

                                {/if}
                                <a  target="_blank" href="{:url('/admin/export_settle',['cp_id'=>$vo['cp_id'],'date_month'=>strtotime($vo['date_month']),'type'=>1])}" class="layui-btn">导出</a>
                            </td>
                        </tr>

                        {/foreach}
                    {else /}
                        <tr>
                            <td style="text-align: center" colspan="11">暂无数据</td>
                        </tr>
                    {/if}
                </tbody>
                </table>
                <!--分页-->
				{:$list->render()}
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
function Settle(element){
    var url = "{:url('/admin/settle/settle')}";
    console.log(url);
    var id = $(element).attr('data-id');
    var date_month = $(element).attr('data-date');
    console.log(id);
    $.post(url,{cp_id:id,date_month:date_month},function(info){
        layer.msg(info.msg);
    })
}

layui.use(['jquery','laydate'],function () {
    var laydate = layui.laydate;
    var $ = layui.$;

    var startDate = layui.laydate.render({
        elem: '#starttime',
        min: '2017-12-28',
        type: 'month',  // 设置为month类型，只选择年月
        format: 'yyyy-MM',  // 设置显示格式为年月
        done: function(value, date) {
            if (value !== '') {
                endDate.config.min.year = date.year;
                endDate.config.min.month = date.month - 1;
                // 对于month类型，date对象可能没有hours/minutes/seconds属性
                endDate.config.btns = ['clear', 'confirm'];
            } else {
                endDate.config.min.year = '';
                endDate.config.min.month = '';
                endDate.config.btns = ['clear', 'now', 'confirm'];
            }
        }
    });

var endDate = layui.laydate.render({
      elem: '#endtime',
      min: '2017-12-28',
    type: 'month',  // 设置为month类型，只选择年月
    format: 'yyyy-MM',  // 设置显示格式为年月
    done: function(value, date) {
        if (value !== '') {
            endDate.config.min.year = date.year;
            endDate.config.min.month = date.month - 1;
            // 对于month类型，date对象可能没有hours/minutes/seconds属性
            endDate.config.btns = ['clear', 'confirm'];
        } else {
            endDate.config.min.year = '';
            endDate.config.min.month = '';
            endDate.config.btns = ['clear', 'now', 'confirm'];
        }
    }
    });
});

</script>
{/block}